home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
editors
/
mntemacs.zoo
/
src
/
keyboard.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-28
|
58KB
|
2,272 lines
/* Keyboard input; editor command loop.
Copyright (C) 1985, 1986, 1987, 1988, 1990 Free Software Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/*** For version 19, can simplify this by making interrupt_input 1 on VMS. */
/* Allow config.h to undefine symbols found here. */
#include <signal.h>
#include "config.h"
#include <stdio.h>
#undef NULL
#include "termchar.h"
#include "termopts.h"
#include "termhooks.h"
#include "lisp.h"
#include "macros.h"
#include "window.h"
#include "commands.h"
#include "buffer.h"
#include <setjmp.h>
#include <errno.h>
extern int errno;
/* Get FIONREAD, if it is available. */
#ifdef USG
#include <termio.h>
#include <fcntl.h>
#else /* not USG */
#ifndef VMS
#include <sys/ioctl.h>
#endif /* not VMS */
#endif /* not USG */
/* Allow m- file to inhibit use of FIONREAD. */
#ifdef BROKEN_FIONREAD
#undef FIONREAD
#endif
/* Make all keyboard buffers much bigger when using X windows. */
#ifdef HAVE_X_WINDOWS
#define BUFFER_SIZE_FACTOR 16
#else
#define BUFFER_SIZE_FACTOR 1
#endif
/* Following definition copied from eval.c */
struct backtrace
{
struct backtrace *next;
Lisp_Object *function;
Lisp_Object *args; /* Points to vector of args. */
int nargs; /* length of vector */
/* if nargs is UNEVALLED, args points to slot holding list of unevalled args */
char evalargs;
};
/* Non-nil disable property on a command means
do not execute it; call disabled-command-hook's value instead. */
Lisp_Object Qdisabled, Vdisabled_command_hook;
int recent_keys_index; /* Index for storing next element into recent_keys */
int total_keys; /* Total number of elements stored into recent_keys */
char recent_keys[100]; /* Holds last 100 keystrokes */
/* Buffer holding the key that invoked the current command. */
char *this_command_keys;
int this_command_key_count; /* Size in use. */
int this_command_keys_size; /* Size allocated. */
extern struct backtrace *backtrace_list;
static jmp_buf getcjmp; /* for longjmp to where kbd input is being done. */
int waiting_for_input; /* True while doing kbd input */
/* True while displaying for echoing. Delays C-g throwing. */
static int echoing;
int immediate_quit; /* Nonzero means C-G should cause immediate error-signal. */
int help_char; /* Character to recognize as the help char. */
Lisp_Object Vhelp_form; /* Form to execute when help char is typed. */
/* Character that causes a quit. Normally C-g. */
int quit_char;
extern Lisp_Object global_map;
/* Current depth in recursive edits. */
int command_loop_level;
/* Last input character read as a command. */
int last_command_char;
/* Last input character read for any purpose. */
int last_input_char;
/* If not -1, a character to be read as the next command input */
int unread_command_char;
/* Char to use as prefix when a meta character is typed in.
This is bound on entry to minibuffer in case Esc is changed there. */
int meta_prefix_char;
/* Total number of times read_command_char has returned. */
int num_input_chars;
/* Auto-save automatically when this many characters have been typed
since the last time. */
static int auto_save_interval;
/* Value of num_input_chars as of last auto save. */
int last_auto_save;
/* Last command executed by the editor command loop, not counting
commands that set the prefix argument. */
Lisp_Object last_command;
/* The command being executed by the command loop.
Commands may set this, and the value set will be copied into last_command
instead of the actual command. */
Lisp_Object this_command;
Lisp_Object Qself_insert_command;
Lisp_Object Qforward_char;
Lisp_Object Qbackward_char;
/* read_key_sequence stores here the command definition of the
key sequence that it reads. */
Lisp_Object read_key_sequence_cmd;
/* Form to evaluate (if non-nil) when Emacs is started */
Lisp_Object Vtop_level;
/* User-supplied string to translate input characters through */
Lisp_Object Vkeyboard_translate_table;
FILE *dribble; /* File in which we write all commands we read */
/* Nonzero if input is available */
int input_pending;
/* Nonzero if should obey 0200 bit in input chars as "Meta" */
int meta_key;
extern char *pending_malloc_warning;
/* Buffer for pre-read keyboard input */
unsigned char kbd_buffer [256 * BUFFER_SIZE_FACTOR];
/* Number of characters available in kbd_buffer. */
int kbd_count;
/* Pointer to next available character in kbd_buffer. */
unsigned char *kbd_ptr;
/* Address (if not 0) of word to zero out
if a SIGIO interrupt happens */
long *input_available_clear_word;
/* Nonzero means use SIGIO interrupts; zero means use CBREAK mode.
Default is 1 if INTERRUPT_INPUT is defined. */
int interrupt_input;
/* Nonzero while interrupts are temporarily deferred during redisplay. */
int interrupts_deferred;
/* nonzero means use ^S/^Q for flow control. */
int flow_control;
#ifndef BSD4_1
#define sigfree() sigsetmask (0)
#define sigholdx(sig) sigsetmask (1 << ((sig) - 1))
#define sigblockx(sig) sigblock (1 << ((sig) - 1))
#define sigunblockx(sig) sigblock (0)
#define sigpausex(sig) sigpause (0)
#endif /* not BSD4_1 */
#ifdef BSD4_1
#define SIGIO SIGTINT
/* sigfree and sigholdx are in sysdep.c */
#define sigblockx(sig) sighold (sig)
#define sigunblockx(sig) sigrelse (sig)
#define sigpausex(sig) sigpause (sig)
#endif /* BSD4_1 */
#ifndef sigmask
#define sigmask(no) (1L << ((no) - 1))
#endif
/* We are unable to use interrupts if FIONREAD is not available,
so flush SIGIO so we won't try. */
#ifndef FIONREAD
#ifdef SIGIO
#undef SIGIO
#endif
#endif
/* If we support X Windows, and won't get an interrupt when input
arrives from the server, poll periodically so we can detect C-g. */
#ifdef HAVE_X_WINDOWS
#ifndef SIGIO
#define POLL_FOR_INPUT
#endif
#endif
/* Function for init_keyboard to call with no args (if nonzero). */
void (*keyboard_init_hook) ();
static void read_avail_input ();
static void get_input_pending ();
/* Non-zero tells input_available_signal to call read_socket_hook
even if FIONREAD returns zero. */
static int force_input;
static int echo_keystrokes; /* > 0 if we are to echo keystrokes */
/* Nonzero means echo each character as typed. */
static int immediate_echo;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
static char echobuf[100];
static char *echoptr;
/* Install the string STR as the beginning of the string of echoing,
so that it serves as a prompt for the next character.
Also start echoing. */
echo_prompt (str)
char *str;
{
int len = strlen (str);
if (len > sizeof echobuf - 4)
len = sizeof echobuf - 4;
bcopy (str, echobuf, len + 1);
echoptr = echobuf + len;
echo ();
}
/* Add the character C to the echo string,
if echoing is going on. */
echo_char (c)
int c;
{
extern char *push_key_description ();
if (immediate_echo)
{
char *ptr = echoptr;
if (ptr - echobuf > sizeof echobuf - 6)
return;
ptr = push_key_description (c, ptr);
*ptr++ = ' ';
if (echoptr == echobuf && c == help_char)
{
strcpy (ptr, "(Type ? for further options) ");
ptr += strlen (ptr);
}
*ptr = 0;
echoptr = ptr;
echo ();
}
}
/* Temporarily add a dash to the end of the echo string,
so that it serves as a mini-prompt for the very next character. */
echo_dash ()
{
if (!immediate_echo && echoptr == echobuf)
return;
/* Put a dash at the end of the buffer temporarily,
but make it go away when the next charac